package com.itboye.ihomebank.db;

import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.itboye.ihomebank.bean.HetongCaoGao;
import com.itboye.ihomebank.bean.TieZiCaoGaoBean;

public class HeTongDBManager {
	HeTongDBHelper mDbHelper;
	SQLiteDatabase db;

	public HeTongDBManager(Context mContext) {
		mDbHelper = new HeTongDBHelper(mContext);
	}

	/**
	 * 添加进草稿
	 * 
	 * @param uid
	 * @param shenfen
	 * @param jsonStr
	 * @return
	 */
	public long addNote(String uid, String contractno, String jsonStr) {
		db = mDbHelper.getWritableDatabase();
		ContentValues cv = new ContentValues();
		cv.put("uid", uid);
		cv.put("contractno", contractno);
		cv.put("jsonstr", jsonStr);
		long num = db.insert("hetong", null, cv);
		db.close();
		return num;
	}

	/**
	 * 
	 * 
	 * @return
	 */
	public String getCaoGaoStr(String uid, String contractNo) {
		db = mDbHelper.getReadableDatabase();
		String jsonstr = "";
		// Cursor mCursor = db.query("hetong", null, "uid=?",
		// new String[] { uid }, null, null, null);
		Cursor mCursor2 = db.rawQuery(
				"select * from hetong where uid=? and contractno=?",
				new String[] { uid, contractNo });
		if (mCursor2 != null) {
			while (mCursor2.moveToNext()) {
				jsonstr = mCursor2.getString(3);
			}
			mCursor2.close();
		}
		db.close();
		return jsonstr;
	}

	public long deleteCaoGao(String uid, String contractNo) {
		db = mDbHelper.getWritableDatabase();
		ContentValues cv = new ContentValues();
		cv.put("uid", uid);
		cv.put("contractno", contractNo);
		long num = db.delete("hetong", "uid=? and contractno=?", new String[] {
				uid, contractNo });
		db.close();
		return num;
	}
}
